package at.fhooe.im440.pandora.logic.entities;

import java.awt.Graphics2D;
import java.util.HashMap;
import java.util.Map;

import at.fhooe.im440.core.Core;
import at.fhooe.im440.pandora.events.KeyPressedEvent;

public class EntityManager {
	
	private Map<String, Entity> entities;
	private Core c;

	public EntityManager(Core core) {
		this.c = core;
		entities = new HashMap<String, Entity>();
	}

	public void addEntity(Entity e) {
		entities.put(e.getName(), e);
	}
	
	public void removeEntity(String name) {
		entities.remove(name);
	}

	public void updateEntities() {
		for(Entity entity : entities.values()){
			entity.update();
		}
	}

	public void renderEntities(Graphics2D g) {
		for(Entity entity : entities.values()){
			entity.render(g);
		}
	}

	public void registerEntityForKeyInput(final Entity e) {
		c.eventMgr.addListener(new KeyPressedEvent.Listener() {
			@Override
			public void onKeyPressed(KeyPressedEvent keyPressedEvent) {
				
				e.notify(keyPressedEvent);
			}
			
		}, "KeyPressed");
	}

}
